#include <iostream>

using namespace std;


typedef class TNode{
public:
	int value;
	TNode *parent;
	TNode *left;
	TNode *right;

public:
	TNode(int data) : value(data), parent(NULL), left(NULL), right(NULL){}
}*Tree;


TNode *findNextNode(TNode *node){
	if(NULL == node)
		return NULL;

	if(NULL == node->right){
		return node->parent;
	}
	else if(NULL == node->left){
		return node->parent;
	}
	else{
		node = node->right;
		while(NULL != node->left)
			node = node->left;

		return node;
	}
}


int nnmain(){
	Tree root = new TNode(3);
	root->left = new TNode(2);
	root->left->parent = root;

	root->right = new TNode(4);
	root->right->parent = root;

	TNode *node = findNextNode(root->right);

	return 0;
}